﻿namespace System.Collections.Generic
{
    /// <summary>
    /// 表示一个分页的集合类型。
    /// </summary>
    /// <typeparam name="T">被分页的类型。</typeparam>
    public class PagedCollection<T> : IReadOnlyCollection<T>
    {
        /// <summary>
        /// 初始化 <see cref="PagedCollection{T}"/> 类的新实例。
        /// </summary>
        public PagedCollection(int currentPage, int itemsPerPage, int totalPages, IEnumerable<T> items, int count)
        {
            this.CurrentPage = currentPage;
            this.ItemsPerPage = itemsPerPage;
            this.TotalPages = totalPages;
            this.Items = items ?? throw new ArgumentNullException(nameof(items));
            this.Count = count;
        }


        /// <summary>
        /// 获取或设置分页的当前页数。
        /// </summary>
        public int CurrentPage { get;internal set; } = 1;

        /// <summary>
        /// 获取或设置分页时每一页呈现的数据量。
        /// </summary>
        public int ItemsPerPage { get;internal set; } = 10;

        /// <summary>
        /// 获取分页的总页码数。
        /// </summary>
        public int TotalPages { get; internal set; }

        /// <summary>
        /// 获取当前分页的项集合。
        /// </summary>
        public IEnumerable<T> Items { get; internal set; }

        /// <summary>
        /// 获取总记录数。
        /// </summary>
        public int Count { get; internal set; }
        

        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns></returns>
        public IEnumerator<T> GetEnumerator() => Items.GetEnumerator();

        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            yield return Items;
        }
    }
}
